/**
 * @fileOverview This file with Sonettic-Cinema HD Player 5 Simple JavaScript API
 * @alias SimpleAPI
 * @author Max Klymyshyn, (c)2009 Sonettic, sonettic-cinema.com, sonettic.com
 * @version 1.0
 */
 
 
/**
 * @func
 * @description method to geting Flash object. Only for internal use.
 * @private
 * @param name player name
 * @return Flash object
 */
function __getSCPlayer(name){
	var isIE = navigator.appName.indexOf("Microsoft") != -1;
	var obj = null;
	try{
		obj = (isIE) ? window[name] : document[name];
	}catch(e){
		throw new Error("Cannot find player [" + name + "]. Details: " + e.message);
	}

	return obj;
}


/**
 * @func
 * @description This is static function to set new video source to the player with name playerName. Usage example:
 * @example
	<pre style='color:#000000;background:#ffffff;'>
<span style='color:#696969; '>// http stream and path from the root of your domain</span>
setContent<span style='color:#808030; '>(</span><span style='color:#0000e6; '>'sonetticFLVPlayer'</span><span style='color:#808030; '>,</span><span style='color:#0000e6; '>'[filename]?start=[seek],/video/Walle1.flv'</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>

<span style='color:#696969; '>// http stream with full path of the video</span>
setContent<span style='color:#808030; '>(</span><span style='color:#0000e6; '>'sonetticFLVPlayer'</span><span style='color:#808030; '>,</span><span style='color:#0000e6; '>'[filename]?start=[seek],http://myhost.com/flv/Walle1.flv'</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>

<span style='color:#696969; '>// progressive download and path from the root of your domain</span>
setContent<span style='color:#808030; '>(</span><span style='color:#0000e6; '>'sonetticFLVPlayer'</span><span style='color:#808030; '>,</span><span style='color:#0000e6; '>'/video/Walle1.flv'</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
	</pre>
 * @param playerName name of the player
 * @param videoPath path to the video, RTMP or HTTP Stream
 * @return void
 */
function setContent(playerName, videoPath){
	try{
		__getSCPlayer(playerName).setContent(videoPath);
	}catch(e){
		throw new Error("setContent(...):Can't change player's content to [" + videoPath + "]. Details: " + e.message);
	}
}

/**
 * @func
 * @deprecated This function used before ver.5 of <a href="http://sonettic-cinema.com/products/players/"><strong>Sonettic-Cinema HD Player</strong></a>.
 * @description This is static function is an alias to setContent and using only for backward compatibility. Use {@link setContent}
 * @param playerName name of the player
 * @param videoPath path to the video, RTMP or HTTP Stream
 * @return void
 */
function setMedia(playerName, videoPath){
	setContent(playerName, videoPath);
}

/** 
 * @func
 * @description This is static function to set position within current video in player <strong>playerName</strong>. It's pretty simple to use it, for example:
 * @example
 	<pre style='color:#000000;background:#ffffff;'>
 	<span style='color:#696969; '>// set position to 60 seconds from start</span>
	setPosition<span style='color:#808030; '>(</span><span style='color:#0000e6; '>'sonetticFLVPlayer'</span><span style='color:#808030; '>,</span><span style='color:#0000e6; '>60</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
	
	<span style='color:#696969; '>// set position to 100 seconds from start</span>
	setPosition<span style='color:#808030; '>(</span><span style='color:#0000e6; '>'sonetticFLVPlayer'</span><span style='color:#808030; '>,</span><span style='color:#0000e6; '>100</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
	</pre>
 * @param playerName name of the player
 * @param {int} positiontime New position of the current movie in seconds
 * @return void
 */
function setPosition(playerName, positiontime){
	try{
		__getSCPlayer(playerName).setPosition(positiontime);
	}catch(e){
		throw new Error("setPosition(...): Can't change video position to " + positiontime + " because " + e.message);
	}
}


/**
 * @func
 * @description This is static function to stop playing of the current video in player <strong>playerName</strong>.
 * @example
	<pre style='color:#000000;background:#ffffff;'>
	<span style='color:#696969; '>// stop playing of video in player sonetticFLVPlayer</span>
	stopMedia<span style='color:#808030; '>(</span><span style='color:#0000e6; '>'sonetticFLVPlayer'</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
	</pre>
 * @param playerName name of the player
 * @return void
 */ 
function stopMedia(playerName){
	try{
		__getSCPlayer(playerName).stopMedia();	
	}catch(e){
		throw new Error("stopMedia(...): Can't stop media because " + e.message);
	}
}

/**
 * @func
 * @description This is static function to pause current video in player <strong>playerName</strong>.
 * @example
	<pre style='color:#000000;background:#ffffff;'>
	<span style='color:#696969; '>// pause playing of video in player sonetticFLVPlayer</span>
	pauseMedia<span style='color:#808030; '>(</span><span style='color:#0000e6; '>'sonetticFLVPlayer'</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
	</pre> 
 * @param playerName name of the player
 * @return void
 */
function pauseMedia(playerName){
	try{
		__getSCPlayer(playerName).pauseMedia();
	}catch(e){
		throw new Error("pauseMedia(...): Can't pause media because " + e.message);
	}
}

/**
 * @func 
 * @description This is static function to play current video in player <strong>playerName</strong>.
 * @example
	<pre style='color:#000000;background:#ffffff;'>
	<span style='color:#696969; '>// lets play media</span>
	playMedia<span style='color:#808030; '>(</span><span style='color:#0000e6; '>'sonetticFLVPlayer'</span><span style='color:#808030; '>)</span><span style='color:#800080; '>;</span>
	</pre> 
 * @param playerName name of the player
 * @return void
 */
function playMedia(playerName){
	try {
		__getSCPlayer(playerName).playMedia();	
	}catch(e){
		throw new Error("playMedia(...): Can't play media because " + e.message);
	}
}

